package org.example.repository;

import org.example.entity.SystemConfig;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

/**
 * 系统配置数据访问接口
 */
@Repository
public interface SystemConfigRepository extends JpaRepository<SystemConfig, Long> {
    
    /**
     * 根据配置键查找配置
     */
    Optional<SystemConfig> findByConfigKey(String configKey);
    
    /**
     * 根据配置键模糊查询
     */
    @Query("SELECT sc FROM SystemConfig sc WHERE sc.configKey LIKE %:key%")
    List<SystemConfig> findByConfigKeyContaining(@Param("key") String key);
    
    /**
     * 检查配置键是否存在
     */
    boolean existsByConfigKey(String configKey);
    
    /**
     * 根据描述模糊查询配置
     */
    @Query("SELECT sc FROM SystemConfig sc WHERE sc.description LIKE %:description%")
    List<SystemConfig> findByDescriptionContaining(@Param("description") String description);
}
